﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using DLL;
namespace BLL
{
   public class NhanVienBLL
    {
       DataServer DB = new DataServer();
       public DataTable Select_All()
       {
           string sql = @"SELECT MaNv, (HoDem+' '+TenNV) as HoTen, NS, NG_VaoLam, DiaChi, DienThoai, Luong, GT, Mail FROM NhanVien where DangLam=1";
           DataTable bang = DB.LayDulieu(sql);
           return bang;
       }
       public bool Them(NhanVienDAL nv)
       {
           string sql = string.Format("sp_NhanVien_Insert");

           string MaTB = DLL.CommonFunc.GetPrimaryKey("NhanVien");
           SqlParameter paramMV = new SqlParameter("@MaNv", MaTB);
           SqlParameter paramHo = new SqlParameter("@HoDem", nv.HoDem);
           SqlParameter paramTen = new SqlParameter("@TenNV", nv.TenNV);
           SqlParameter paramNS = new SqlParameter("@NS", nv.NS);
           SqlParameter paramNVL = new SqlParameter("@NG_VaoLam", nv.NG_VaoLam);
           SqlParameter paramDC = new SqlParameter("@DiaChi", nv.DiaChi);
           SqlParameter paramDT = new SqlParameter("@DienThoai", nv.DienThoai);
           SqlParameter paramL = new SqlParameter("@Luong", nv.Luong);
           SqlParameter paramGT = new SqlParameter("@GT", nv.GT);
           SqlParameter paramEmail = new SqlParameter("@Mail", nv.EMail);
           SqlParameter paramMK = new SqlParameter("@MatKhau", nv.Pass);
           SqlParameter paramDL = new SqlParameter("@DangLam", nv.DangLam);
           SqlParameter paramQ = new SqlParameter("@Quyen", nv.Quyen);
           try
           {
               DB.CapNhatProc(sql, paramMV, paramHo, paramTen, paramNS, paramNVL, paramDC, paramDT, paramL, paramGT, paramEmail, paramMK, paramDL,paramQ);
           }
           catch
           {
               return false;
           }
           DLL.CommonFunc.UpdatePrimaryKey("NhanVien");
           return true;
       }
       public bool Sua(NhanVienDAL nv)
       {
           string sql = string.Format("sp_NhanVien_Update");
           SqlParameter paramMV = new SqlParameter("@MaNv", nv.MaNv);
           SqlParameter paramHo = new SqlParameter("@HoDem", nv.HoDem);
           SqlParameter paramTen = new SqlParameter("@TenNV", nv.TenNV);
           SqlParameter paramNS = new SqlParameter("@NS", nv.NS);
           SqlParameter paramNVL = new SqlParameter("@NG_VaoLam", nv.NG_VaoLam);
           SqlParameter paramDC = new SqlParameter("@DiaChi", nv.DiaChi);
           SqlParameter paramDT = new SqlParameter("@DienThoai", nv.DienThoai);
           SqlParameter paramL = new SqlParameter("@Luong", nv.Luong);
           SqlParameter paramGT = new SqlParameter("@GT", nv.GT);
           SqlParameter paramEmail = new SqlParameter("@Mail", nv.EMail);
           SqlParameter paramMK = new SqlParameter("@MatKhau", nv.Pass);
           SqlParameter paramDL = new SqlParameter("@DangLam", nv.DangLam);
           try
           {
               DB.CapNhatProc(sql, paramMV, paramHo, paramTen, paramNS, paramNVL, paramDC, paramDT, paramL, paramGT, paramEmail, paramMK, paramDL);
           }
           catch
           {
               return false;
           }
           return true;
       }
       public bool Xoa(string MaNV)
       {
           string sql = string.Format("sp_NhanVien_Delete");
           SqlParameter paramMV = new SqlParameter("@MaNv",MaNV);
          
               DB.CapNhatProc(sql, paramMV);
         
           return true;
       }
       public DataTable Search(NhanVienDAL nv)
       {
           string sql = string.Format("sp_NhanVien_Search");
           SqlParameter paramMTB = new SqlParameter("@MaNv", nv.MaNv);
           SqlParameter paramTTB = new SqlParameter("@TenNV", nv.TenNV);
            SqlParameter paramHD = new SqlParameter("@HoDem", nv.HoDem);
           DataTable bang = DB.LayDuLieuProc(sql, paramMTB, paramTTB,paramHD);
           return bang;
       }
    }
}
